home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pcmagazi / 1989 / 11 / inishow.c < prev    next >
Text File  |  1989-05-05  |  6KB  |  157 lines

  1. /*------------------------------------------------------
  2.    INISHOW.C - Displays OS2.INI Information in OS/2 1.1
  3.                (C) 1989, Ziff Communications Co.
  4.                PC Magazine * Charles Petzold, 1/89
  5.   ------------------------------------------------------*/
  6.  
  7. #define  INCL_WINSHELLDATA
  8. #include <os2.h>
  9. #include <ctype.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #define  BYTES 8    // Bytes of binary data per display line
  15.  
  16. int main (void)
  17.      {
  18.      BOOL   fIsString ;
  19.      CHAR   szBuffer[4 * BYTES + 10] ;
  20.      HAB    hab ;
  21.      INT    iQueryApp, iQueryKey, iOff, iByte, iLen ;
  22.      UCHAR  *pchQueryApp, *pchQueryKey, *pchQueryStr ;
  23.      USHORT cbData ;
  24.  
  25.      hab = WinInitialize (0) ;
  26.                                    // Allocate memory for application names
  27.  
  28.      if (WinQueryProfileSize (hab, NULL, NULL, &cbData))
  29.           {
  30.           fputs ("INISHOW: Cannot obtain any profile data.\n", stderr) ;
  31.           return 1 ;
  32.           }
  33.  
  34.      if (NULL == (pchQueryApp = malloc (cbData)))
  35.           {
  36.           fputs ("INISHOW: Cannot allocate memory for application names.\n",
  37.                  stderr) ;
  38.           return 1 ;
  39.           }
  40.                                    // Get list of application names and scan
  41.  
  42.      WinQueryProfileString (hab, NULL, NULL, "", pchQueryApp, cbData) ;
  43.      iQueryApp = 0 ;
  44.  
  45.      while (pchQueryApp[iQueryApp] != '\0')
  46.           {
  47.           printf ("[%s]\n", pchQueryApp + iQueryApp) ;
  48.  
  49.                                         // Allocate memory for key names
  50.  
  51.           WinQueryProfileSize (hab, pchQueryApp + iQueryApp, NULL, &cbData) ;
  52.  
  53.           if (NULL == (pchQueryKey = malloc (cbData)))
  54.                {
  55.                fputs ("INISHOW: Cannot allocate memory for key names.\n",
  56.                       stderr) ;
  57.                return 1 ;
  58.                }
  59.                                         // Get list of key names and scan
  60.  
  61.           WinQueryProfileString (hab, pchQueryApp + iQueryApp, NULL, "",
  62.                                       pchQueryKey, cbData) ;
  63.           iQueryKey = 0 ;
  64.  
  65.           while (pchQueryKey[iQueryKey] != '\0')
  66.                {
  67.                                              // Get size of data
  68.  
  69.                WinQueryProfileSize (hab, pchQueryApp + iQueryApp,
  70.                                          pchQueryKey + iQueryKey, &cbData) ;
  71.  
  72.                if (NULL == (pchQueryStr = malloc (cbData)))
  73.                     {
  74.                     fputs ("INISHOW: Cannot allocate memory for data.\n",
  75.                            stderr) ;
  76.                     return 1 ;
  77.                     }
  78.  
  79.                printf ("\t[%s]%s\n", pchQueryKey + iQueryKey,
  80.                                      cbData == 0 ? " -- NO DATA -- " : "") ;
  81.                if (cbData == 0)
  82.                     continue ;
  83.                                              // Determine if data is string
  84.                                              // or stored in a binary format
  85.  
  86.                fIsString = (cbData > 1) ? TRUE : FALSE ;
  87.  
  88.                if (fIsString)
  89.                     {
  90.                     WinQueryProfileString (hab, pchQueryApp + iQueryApp,
  91.                                                 pchQueryKey + iQueryKey, "",
  92.                                                 pchQueryStr, cbData) ;
  93.  
  94.                                              // Check if string length matches
  95.  
  96.                     if (cbData != strlen (pchQueryStr) + 1)
  97.                          fIsString = FALSE ;
  98.                     }
  99.                                              // Check for printable characters
  100.                if (fIsString)
  101.                     for (iByte = 0 ; iByte < cbData - 1 ; iByte++)
  102.                          if (!isprint (pchQueryStr[iByte]))
  103.                               fIsString = FALSE ;
  104.  
  105.                                              // If a string, display it
  106.                if (fIsString)
  107.                     printf ("\t\t%s\n", pchQueryStr) ;
  108.  
  109.                                              // If not, dump it
  110.                else
  111.                     {
  112.                     WinQueryProfileData (hab, pchQueryApp + iQueryApp,
  113.                                               pchQueryKey + iQueryKey,
  114.                                               pchQueryStr, &cbData) ;
  115.  
  116.                     for (iOff = 0 ; iOff < cbData ; iOff += BYTES)
  117.                          {
  118.                          iLen = sprintf (szBuffer, "\t\t%04X  ", iOff) ;
  119.  
  120.                          for (iByte = iOff ; iByte < iOff + BYTES ; iByte++)
  121.                               {
  122.                               if (iByte < cbData)
  123.                                    iLen += sprintf (szBuffer + iLen, "%02X ",
  124.                                                     pchQueryStr[iByte]) ;
  125.                               else
  126.                                    iLen = strlen (strcat (szBuffer, "   ")) ;
  127.                               }
  128.                          szBuffer[iLen++] = ' ' ;
  129.  
  130.                          for (iByte = iOff ; iByte < iOff + BYTES ; iByte++)
  131.                               {
  132.                               if (iByte < cbData)
  133.                                    if (isprint (pchQueryStr[iByte]))
  134.                                         szBuffer[iLen++] = pchQueryStr[iByte] ;
  135.                                    else
  136.                                         szBuffer[iLen++] = '.' ;
  137.                               else
  138.                                    szBuffer[iLen++] = ' ' ;
  139.                               }
  140.                          szBuffer[iLen] = '\0' ;
  141.                          puts (szBuffer) ;
  142.                          }
  143.                     }
  144.                                              // Next key name
  145.                free (pchQueryStr) ;
  146.                iQueryKey += strlen (pchQueryKey + iQueryKey) + 1 ;
  147.                }
  148.                                         // Next application name
  149.           free (pchQueryKey) ;
  150.           iQueryApp += strlen (pchQueryApp + iQueryApp) + 1 ;
  151.           }
  152.                                    // Clean up and terminate
  153.      free (pchQueryApp) ;
  154.      WinTerminate (hab) ;
  155.      return 0 ;
  156.      }
  157.